<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>CSS 瀑布流布局</title>
    <style>
      body {
        margin: 0;
        padding: 20px;
      }

      .waterfall-container {
        /* 设置列数，可根据需要调整 */
        column-count: 3;
        /* 设置列间距 */
        column-gap: 20px;
      }

      .item {
        /* 避免元素跨列显示 */
        break-inside: avoid;
        margin-bottom: 20px;
        box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
        border-radius: 5px;
        padding: 10px;
        box-sizing: border-box;
      }

      .item img {
        width: 100%;
        display: block;
      }

      @media (max-width: 768px) {
        .waterfall-container {
          column-count: 2;
        }
      }

      @media (max-width: 480px) {
        .waterfall-container {
          column-count: 1;
        }
      }
    </style>
  </head>

  <body>
    <div class="waterfall-container">
      <div class="item">
        <img src="https://via.placeholder.com/200x300" alt="图片 1" />
        <p>图片 1</p>
      </div>
      <div class="item">
        <img src="https://via.placeholder.com/200x200" alt="图片 2" />
        <p>图片 2</p>
      </div>
      <div class="item">
        <img src="https://via.placeholder.com/200x250" alt="图片 3" />
        <p>图片 3</p>
      </div>
      <div class="item">
        <img src="https://via.placeholder.com/200x350" alt="图片 4" />
        <p>图片 4</p>
      </div>
      <div class="item">
        <img src="https://via.placeholder.com/200x220" alt="图片 5" />
        <p>图片 5</p>
      </div>
      <div class="item">
        <img src="https://via.placeholder.com/200x280" alt="图片 6" />
        <p>图片 6</p>
      </div>
      <div class="item">
        <img src="https://via.placeholder.com/200x320" alt="图片 7" />
        <p>图片 7</p>
      </div>
      <div class="item">
        <img src="https://via.placeholder.com/200x240" alt="图片 8" />
        <p>图片 8</p>
      </div>
      <div class="item">
        <img src="https://via.placeholder.com/200x260" alt="图片 9" />
        <p>图片 9</p>
      </div>
      <div class="item">
        <img src="https://via.placeholder.com/200x310" alt="图片 10" />
        <p>图片 10</p>
      </div>
    </div>
  </body>
</html>
